<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
//header('WWW-Authenticate: Basic realm="localhost"');
if (!isset($_SERVER['PHP_AUTH_USER'])) 
{
    header('WWW-Authenticate: Basic realm="localhost"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} 
else 
{
	$db = mysql_connect('localhost','root','') or die("Couldn't connect to the database.");
	mysql_select_db('cankidsdonordb_production') or die("Couldn't select the database"); 
    //echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    //echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
$pass = $_SERVER['PHP_AUTH_PW'];
$user = $_SERVER['PHP_AUTH_USER'];

	$result = mysql_query("SELECT count(userid) FROM users WHERE last_name='$pass' AND first_name='$user'") or die("Couldn't query the user-database.");
      $num = mysql_result($result, 0);

	if($num)
	{
		echo "sucessful login";
		setcookie("user", $user, time()+3600);
	}
	else
	{
		echo "unsucessful login";
	}
}
?>

<!--
<SCRIPT LANGUAGE="JavaScript">

cookie_name = "LoginCookie";
var YouEntered;

function putCookie() {

if(document.cookie != document.cookie)
{index = document.cookie.indexOf(cookie_name);}
else
{ index = -1;}

if (index == -1)
{
YouEntered=document.cf.cfd.value;
document.cookie=cookie_name+"="+YouEntered+"; expires=Monday, 04-Aug-2010 05:00:00 GMT";
}

}
</SCRIPT>

<FORM NAME="cf" action="login.php" method="get">

<INPUT TYPE="text" NAME="username" value="Username" size="20" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
<input type="text" name="pword" value="Password" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
<INPUT TYPE="button" Value="Login" onClick="putCookie()">

</FORM>
-->